<?php 
// include "GenFunction.php";
?>
		
<?php
Class Gen_Telephones
{
	var$Table;
	
	//поля
	var $id;
	var $tel;//при загрузке надо отсортировать по датетайму
	var $date1;
	var $date2;
	var $pr_id;
	
		function Gen_Telephones($array_pr_id=array(),$num_tel_max=3)
	{
		if(empty($array_pr_id))$array_pr_id=array_int_noreapet_autoGen(50);
		
		$this->CreateTable();
		
		foreach($array_pr_id as $pr_id)
		{
			$num_tel=rand(1,$num_tel_max);
			for($n=1;$n<=$num_tel;$n++)
			{
				$this->id++;
				$this->tel='89'.fun(rand(0,99)).fun(rand(0,99)).fun(rand(0,99)).fun(rand(0,99)).rand(0,9);
				
				$date1=gen_date();
				list($year, $month,$day) = split ('-', $date1);
				$date2=($year+rand(1,9)).'-'.$month.'-'.$day;
				
				$this->date1=$date1;
				$this->date2=$date2;
				$this->pr_id=$pr_id;
				
				$this->InsertData();
				// $this->Show_row();
			}
		}
		echo $this->db_query.'<br><br>';
	}
	
	function CreateTable()
		{
		//echo
			$this->db_query.="CREATE TABLE `telephones` (
  `id` int(11) NOT NULL auto_increment,
  `tel` varchar(20) character set utf8 NOT NULL,
  `date1` date default NULL,
  `date2` date default NULL,
  `pr_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  FOREIGN KEY (pr_id) REFERENCES projects(id)
           ON UPDATE CASCADE
           ON DELETE CASCADE
       ) ENGINE=InnoDB CHARACTER SET=UTF8;
".'<br><br>';
		}
		
		
			function InsertData()
		{
			$id=$this->id;
			$tel=$this->tel;
			$date1=$this->date1;
			$date2=$this->date2;
			$pr_id=$this->pr_id;
			$this->db_query.="INSERT INTO `telephones` VALUES ($id, '$tel', '$date1', '$date2','$pr_id');"."<br>";
		}			
	
		function Show_row()
		{
			echo$this->id.'	';
			echo$this->tel.'	';
			echo$this->date1.'	';
			echo$this->date2.'	';
			echo$this->pr_id.'	';
			echo '<br>';
		}
}

// $g_t=new Gen_Telephones();






?>

  <?php //mysql_close($conn); ?>